connect = require '../utils/connect'
module.exports = 
	'get /:id':(req, res)->
		id = req.params.id
		sql = "select * from staves where id = ?"
		connect.queryOne sql, [id], (err, result)->
			console.log err if err
			local = 
				stave:result
			res.render 'stave/detail',local


	'get ': (req, res)->
		order = req.query.order || 'id'
		page = req.query.page || 0
		sql = "select * from staves order by #{order} desc limit ?,100"
		connect.runSql sql, [ 100*page], (err,result)->
			console.log err if err
			res.render 'stave/list',{staves:result}

	'get /search/like': (req, res)->
		kw = req.query.kw
		sql = "select * from staves where name like '%#{kw}%' or content like '%#{kw}%' limit 20"
		connect.runSql sql, (err, result)->
			console.log err if err
			res.render 'stave/list',{staves:result}

	'get /search/singer':(req, res)->
		name = req.query.name
		sql = "select * from staves where singer = ?"
		connect.runSql sql, [name], (err, result)->
			console.log err if err
			res.render 'stave/list',{staves:result}